<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui" 
	xmlns:pe="http://primefaces.org/ui/extensions"
	xmlns:of="http://omnifaces.org/functions"
	template="/WEB-INF/templates/template.xhtml">
	
<ui:define name="headIncludes">
	<f:event listener="#{compraBean.initializeDetail(param.numNota, param.numSerie, param.fornecedorId)}" type="preRenderView"/>
	
	<style>
		.panel300 {
			width: 300px;
		}
		.panel120 {
			width: 120px;
		}
		.panel80 {
			width: 80px;
		}
	</style>
</ui:define>
	
	<ui:define name="pageName">Detalhe de Compra</ui:define>
	
	<ui:define name="buttons">	
		<p:commandButton value="Cancelar compra" style="height:28px;" actionListener="#{compraBean.openDialogConfirmCancel}" rendered="#{compraBean.currentCompra.status != 'CANCELADA'}" id="btCancelar" icon="ui-icon-cancel"/>
		<p:commandButton value="Voltar" style="height:28px;" action="#{compraBean.changeToList}" process="@this" icon="ui-icon-arrowreturnthick-1-w"/>
	</ui:define>
	
	<ui:define name="content">
		<p:panel>
			<div>
				<p:messages autoUpdate="true" id="messageDetailCompra" closable="true"/>
				
				<h:panelGrid columns="1" id="panelStatus">
					<h:outputText style="font-weight:bold;padding:7px;" value="Status da compra: #{compraBean.currentCompra.status}" rendered="#{compraBean.currentCompra.status == 'CANCELADA'}"/>				
				</h:panelGrid>
				<h:panelGrid columns="5" style="padding:5px;" columnClasses="panel120, panel80, panel300">
					<h:outputText style="font-weight:bold;padding:7px;" value="Número da nota" />
					<h:outputText style="font-weight:bold;padding:7px;" value="Série" />
					<h:outputText style="font-weight:bold;padding:7px;" value="Fornecedor" />
					<h:outputText style="font-weight:bold;padding:7px;" value="Data de emissão" />
					<h:outputText style="font-weight:bold;padding:7px;" value="Data de chegada" />
					
					<h:outputText style="padding:7px;" value="#{compraBean.currentCompra.notaPK.numeroNota}"/>
					<h:outputText style="padding:7px;" value="#{compraBean.currentCompra.notaPK.numeroSerie}"/>
					<h:outputText style="padding:7px;" value="#{of:abbreviate(compraBean.currentCompra.fornecedor.nome, 60)}"/>					
					<h:outputText style="padding:7px;" value="#{compraBean.currentCompra.emissao}">
						<f:convertDateTime pattern="dd/MM/yyyy"/>
					</h:outputText>
					<h:outputText style="padding:7px;" value="#{compraBean.currentCompra.chegada}" >
						<f:convertDateTime pattern="dd/MM/yyyy"/>
					</h:outputText>					
				</h:panelGrid>
				
				<div style="padding-top:10px; padding-bottom:10px;">
					<p:dataTable emptyMessage="Não há registros"
						id="tableItensCompra" value="#{compraBean.currentCompra.itensCompra}"
						var="item">						
						<p:columnGroup type="header">  
				            <p:row>
				            	<p:column rowspan="2" headerText="Cód." width="25"/>			 
								<p:column rowspan="2" headerText="Produto"/> 
								<p:column rowspan="2" headerText="Qtde." width="40"/>
								<p:column rowspan="2" headerText="V. unit." width="50"/>
								<p:column rowspan="2" headerText="V. total" width="50"/>
								<p:column rowspan="2" headerText="BC ICMS" width="40"/>
								<p:column rowspan="2" headerText="V. ICMS" width="40"/>
								<p:column rowspan="2" headerText="V. IPI" width="40"/>
								<p:column rowspan="2" headerText="BC ICMS Subst" width="40"/>
								<p:column rowspan="2" headerText="V. ICMS Subst" width="40"/>
				                <p:column colspan="3" headerText="Alíquotas" /> 
				            </p:row>  
				  
				            <p:row>  
				                <p:column headerText="ICMS" width="20"/>  
				                <p:column headerText="IPI" width="20"/>  
				                <p:column headerText="ICMS Subst" width="30"/>  
				            </p:row>  
				        </p:columnGroup>
				        
		            	<p:column style="text-align:center;">  
					    	#{item.produto.id} 
						</p:column>				 
						<p:column>  
					    	#{item.produto.descricao}  
						</p:column> 
						<p:column style="text-align:center;">  
					    	#{item.quantidade}  
						</p:column>
						<p:column style="text-align:center;">  
					    	<h:outputText value="#{item.valor}">
				    			<f:convertNumber pattern="#,###,##0.00" />
				    		</h:outputText> 
						</p:column>
						<p:column style="text-align:center;">  
					    	<h:outputText value="#{item.total}">
				    			<f:convertNumber pattern="#,###,##0.00" />
				    		</h:outputText>		  
						</p:column>
						<p:column style="text-align:center;">  
					    	<h:outputText value="#{item.bcIcms}">
				    			<f:convertNumber pattern="#,###,##0.00" />
				    		</h:outputText>		  
						</p:column>
						<p:column style="text-align:center;">  
					    	<h:outputText value="#{item.valorIcms}">
				    			<f:convertNumber pattern="#,###,##0.00" />
				    		</h:outputText>		  
						</p:column>
						<p:column style="text-align:center;">  
					    	<h:outputText value="#{item.valorIpi}">
				    			<f:convertNumber pattern="#,###,##0.00" />
				    		</h:outputText>		  
						</p:column>
						
						<p:column style="text-align:center;">  
					    	<h:outputText value="#{item.bcIcmsSubs}">
				    			<f:convertNumber pattern="#,###,##0.00" />
				    		</h:outputText>		  
						</p:column>
						
						<p:column style="text-align:center;">  
					    	<h:outputText value="#{item.valorIcms}">
				    			<f:convertNumber pattern="#,###,##0.00" />
				    		</h:outputText>		  
						</p:column>
						
						<p:column style="text-align:center;">  
					    	<h:outputText value="#{item.percentualIcms}">
				    			<f:convertNumber pattern="#,###,##0.00" />
				    		</h:outputText>		  
						</p:column>
						
						<p:column style="text-align:center;">  
					    	<h:outputText value="#{item.percentualIpi}">
				    			<f:convertNumber pattern="#,###,##0.00" />
				    		</h:outputText>		  
						</p:column>
						
						<p:column style="text-align:center;">  
					    	<h:outputText value="#{item.percentualIcmsSubs}">
				    			<f:convertNumber pattern="#,###,##0.00" />
				    		</h:outputText>		  
						</p:column>
				  	</p:dataTable>
				</div>
				
				<h:panelGrid columns="5" style="padding:5px;">
					<h:outputText style="font-weight:bold;padding:7px;" value="BC ICMS"/>
					<h:outputText style="font-weight:bold;padding:7px;" value="Valor ICMS"/>
					<h:outputText style="font-weight:bold;padding:7px;" value="BC ICMS Subst."/>
					<h:outputText style="font-weight:bold;padding:7px;" value="Valor ICMS Subst."/>
					<h:outputText style="font-weight:bold;padding:7px;" value="Total dos produtos"/>
									
					<h:outputText style="padding:7px;" value="#{compraBean.currentCompra.bcIcms}">
						<f:convertNumber pattern="R$ #,###,##0.00" />
				    </h:outputText>
					<h:outputText style="padding:7px;" value="#{compraBean.currentCompra.valorIcms}">
						<f:convertNumber pattern="R$ #,###,##0.00" />
				    </h:outputText>
					<h:outputText style="padding:7px;" value="#{compraBean.currentCompra.bcIcmsSubs}">
						<f:convertNumber pattern="R$ #,###,##0.00" />
				    </h:outputText>
					<h:outputText style="padding:7px;" value="#{compraBean.currentCompra.valorIcmsSubs}">
						<f:convertNumber pattern="R$ #,###,##0.00" />
				    </h:outputText>
					<h:outputText style="padding:7px;" value="#{compraBean.totalItensNota}" id="totalItens">
						<f:convertNumber pattern="R$ #,###,##0.00" />
				    </h:outputText>
				</h:panelGrid>
				
				<h:panelGrid columns="6" style="padding:5px;">
					<h:outputText style="font-weight:bold;padding:7px;" value="Valor frete"/>
					<h:outputText style="font-weight:bold;padding:7px;" value="Valor seguro"/>
					<h:outputText style="font-weight:bold;padding:7px;" value="Desconto (%)"/>
					<h:outputText style="font-weight:bold;padding:7px;" value="Outras despesas"/>
					<h:outputText style="font-weight:bold;padding:7px;" value="Valor IPI"/>
					<h:outputText style="font-weight:bold;padding:7px;" value="Total da nota"/>
									
					<h:outputText style="padding:7px;" value="#{compraBean.currentCompra.valorFrete}">
						<f:convertNumber pattern="R$ #,###,##0.00" />
				    </h:outputText>
					<h:outputText style="padding:7px;" value="#{compraBean.currentCompra.valorSeguro}">
						<f:convertNumber pattern="R$ #,###,##0.00" />
				    </h:outputText>
					<h:outputText style="padding:7px;" value="#{compraBean.currentCompra.desconto}">
						<f:convertNumber pattern="#,###,##0.00" />
				    </h:outputText>
					<h:outputText style="padding:7px;" value="#{compraBean.currentCompra.outrasDespesas}">
						<f:convertNumber pattern="R$ #,###,##0.00" />
				    </h:outputText>
					<h:outputText style="padding:7px;" value="#{compraBean.currentCompra.valorIpi}">
						<f:convertNumber pattern="R$ #,###,##0.00" />
				    </h:outputText>
					<h:outputText style="padding:7px;" value="#{compraBean.currentCompra.totalNota}" id="totalNota">
						<f:convertNumber pattern="R$ #,###,##0.00" />
				    </h:outputText>
				</h:panelGrid>
				
				<h:panelGrid columns="1" style="padding:5px;">
					<h:outputText style="font-weight:bold;padding:7px;" value="Condição de pagamento"/>
									
					<h:outputText style="padding:7px;" value="#{compraBean.currentCompra.condicaoPagamento.condicaoPagamento}"/>
				</h:panelGrid>
				
				<div style="padding-top:10px; padding-bottom:10px;">
					<p:dataTable emptyMessage="Não há registros" style="width:500px;" value="#{compraBean.contasPagar}" 
						var="conta" rowIndexVar="index" id="tableContasPagar">
												
						<p:column headerText="Parcela" style="width:50px; text-align:center;" >  
					    	<h:outputText value="#{index + 1}"/>  
						</p:column>				 
						<p:column headerText="Vencimento" style="width:100px; text-align:center;">  
					    	<h:outputText value="#{conta.dataVencimento}">
								<f:convertDateTime pattern="dd/MM/yyyy"/>
							</h:outputText>  
						</p:column> 
						<p:column headerText="Valor" style="width:100px; text-align:center;">  
					    	<h:outputText value="#{conta.valor}">
				    			<f:convertNumber pattern="R$ #,###,##0.00" />
				    		</h:outputText>   
						</p:column>
						
						<p:column headerText="Status" width="60" style="text-align:center;">
							<h:outputText value="#{conta.status}"/>
						</p:column>
				  	</p:dataTable>
				</div>
			</div>
		</p:panel>				
	</ui:define>
	<ui:define name="popups">
				
		<p:dialog appendToBody="true" modal="true" closable="false" widgetVar="popupConfirmCancel"
			width="340" resizable="false" header="Confirmação" height="75">
			<h:form>
				<div style="margin-top: 10px;">
					<h:outputText value="Confirma o cancelamento da compra?"/>
				</div>
				<div align="right" style="margin-top: 15px;">
					<p:commandButton value="Confirmar" actionListener="#{compraBean.cancelarCompra}" oncomplete="popupConfirmCancel.hide()" icon="ui-icon-check"/>
					<p:commandButton value="Cancelar" onclick="popupConfirmCancel.hide()" icon="ui-icon-cancel"/>
				</div>		
			</h:form>			
		</p:dialog>
		
	</ui:define>
</ui:composition>